
package com.meida.module.bus.provider.controller;

import com.meida.common.annotation.RlockRepeat;
import com.meida.common.lock.LockConstant;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.springmvc.base.BaseController;
import com.meida.module.bus.client.entity.AppUserExtra;
import com.meida.module.bus.provider.service.AppUserExtraService;
import com.meida.module.user.client.entity.AppUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/appUserExtra/")
@Api(tags = "用户扩展字段")
public class AppUserExtraController extends BaseController<AppUserExtraService, AppUserExtra> {
    public AppUserExtraController() {
    }

    @ApiOperation(value = "实名认证", notes = "实名认证")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "删除实名认证", notes = "删除实名认证")
    @PostMapping(value = "removeIdCard")
    public ResultBody removeIdCard(@RequestParam(required = false) Long id) {
        return bizService.removeIdCard(id);
    }

    @ApiOperation(value = "查询会员信息", notes = "查询会员信息")
    @GetMapping(value = "getAppUserVipInfo")
    public ResultBody getAppUserVipInfo(@RequestParam(required = false) Long id) {
        return ResultBody.ok(bizService.getAppUserVipInfo(id));
    }

    /**
     * 绑定手机号,并调用初始化登录方法
     */
    @ApiOperation(value = "绑定手机号", notes = "绑定后调用初始化登录方法")
    @PostMapping("bindMobile")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", required = true, value = "手机号", paramType = "form", defaultValue = "18739941307"),
            @ApiImplicitParam(name = "areaCode", required = false, value = "国际区号", paramType = "form", defaultValue = "+86"),
            @ApiImplicitParam(name = "smsCode", required = true, value = "验证码", paramType = "form"),
            @ApiImplicitParam(name = "shareCode", required = false, value = "邀请码", paramType = "form"),
            @ApiImplicitParam(name = "userType", required = true, value = "用户类型,当手机号未注册时传递", paramType = "form"),
            @ApiImplicitParam(name = "password", value = "密码,当手机号未注册时可设置密码,默认123456", paramType = "form")
    })
    @RlockRepeat(prefix = "register", lockConstant = LockConstant.SUBMIT)
    public ResultBody<AppUser> bindMobile(
            @RequestParam(value = "mobile") String mobile,
            @RequestParam(value = "areaCode", required = false) String areaCode,
            @RequestParam(value = "password", required = false) String password,
            @RequestParam(value = "smsCode") String smsCode,
            @RequestParam(value = "shareCode") String shareCode,
            @RequestParam(value = "userType", required = false) String userType
    ) {
        return bizService.bingMobile(mobile, areaCode, smsCode, password, shareCode, userType);
    }
}
